import request from '@/utils/request'

// 分页查询订单列表
export function getOrderList(params) {
  return request({
    url: '/system/battery-order/list',
    method: 'get',
    params
  })
}

// 查询待确认订单列表
export function getPendingOrders() {
  return request({
    url: '/system/battery-order/pending',
    method: 'get'
  })
}

// 查询进行中的订单列表
export function getInProgressOrders() {
  return request({
    url: '/system/battery-order/in-progress',
    method: 'get'
  })
}

// 根据ID查询订单详情
export function getOrderDetailById(orderId) {
  return request({
    url: `/system/battery-order/${orderId}`,
    method: 'get'
  })
}

// 根据订单ID查询订单详情列表
export function getOrderDetailsByOrderId(orderId) {
  return request({
    url: `/system/battery-order/${orderId}/details`,
    method: 'get'
  })
}

// 系统生成换电订单
export function generateSystemOrder(params) {
  return request({
    url: '/system/battery-order/generate',
    method: 'post',
    params
  })
}

// 手动创建换电订单
export function createManualOrder(data) {
  return request({
    url: '/system/battery-order/create',
    method: 'post',
    data
  })
}

// 调度员确认订单
export function confirmOrder(orderId, remark) {
  return request({
    url: `/system/battery-order/${orderId}/confirm`,
    method: 'post',
    params: { remark }
  })
}

// 取消订单
export function cancelOrder(orderId, reason) {
  return request({
    url: `/system/battery-order/${orderId}/cancel`,
    method: 'post',
    params: { reason }
  })
}

// 开始执行订单
export function startOrder(orderId) {
  return request({
    url: `/system/battery-order/${orderId}/start`,
    method: 'post'
  })
}

// 完成订单
export function completeOrder(orderId) {
  return request({
    url: `/system/battery-order/${orderId}/complete`,
    method: 'post'
  })
}

// 更新订单详情状态
export function updateOrderDetailStatus(detailId, status, batteryNo) {
  return request({
    url: `/system/battery-order/detail/${detailId}/status`,
    method: 'post',
    params: { status, batteryNo }
  })
}

// 获取订单统计信息
export function getOrderStatistics() {
  return request({
    url: '/system/battery-order/statistics',
    method: 'get'
  })
}

// 获取今日订单统计
export function getTodayOrderStatistics() {
  return request({
    url: '/system/battery-order/statistics/today',
    method: 'get'
  })
}

// 获取订单创建选项数据
export function getOrderCreateOptions() {
  return request({
    url: '/system/battery-order/create-options',
    method: 'get'
  })
}

// 手动触发系统订单生成
export function triggerGenerateSystemOrders() {
  return request({
    url: '/system/battery-order/trigger-generate',
    method: 'post'
  })
}

// 换电平台管理相关接口

// 获取换电平台列表
export function getChargingPlatformList(params) {
  return request({
    url: '/system/charging-platform/list',
    method: 'get',
    params
  })
}

// 新增换电平台
export function addChargingPlatform(data) {
  return request({
    url: '/system/charging-platform',
    method: 'post',
    data
  })
}

// 修改换电平台
export function updateChargingPlatform(data) {
  return request({
    url: '/system/charging-platform',
    method: 'put',
    data
  })
}

// 删除换电平台
export function deleteChargingPlatform(platformId) {
  return request({
    url: `/system/charging-platform/${platformId}`,
    method: 'delete'
  })
}

// 换电车管理相关接口

// 获取换电车列表
export function getBatteryTruckList(params) {
  return request({
    url: '/system/battery-truck/list',
    method: 'get',
    params
  })
}

// 新增换电车
export function addBatteryTruck(data) {
  return request({
    url: '/system/battery-truck',
    method: 'post',
    data
  })
}

// 修改换电车
export function updateBatteryTruck(data) {
  return request({
    url: '/system/battery-truck',
    method: 'put',
    data
  })
}

// 删除换电车
export function deleteBatteryTruck(truckId) {
  return request({
    url: `/system/battery-truck/${truckId}`,
    method: 'delete'
  })
}

// 更新换电车状态
export function updateBatteryTruckStatus(truckId, status) {
  return request({
    url: `/system/battery-truck/${truckId}/status`,
    method: 'put',
    data: { status }
  })
}

// 电池管理相关接口

// 获取电池列表
export function getBatteryList(params) {
  return request({
    url: '/system/battery/list',
    method: 'get',
    params
  })
}

// 新增电池
export function addBattery(data) {
  return request({
    url: '/system/battery',
    method: 'post',
    data
  })
}

// 修改电池
export function updateBattery(data) {
  return request({
    url: '/system/battery',
    method: 'put',
    data
  })
}

// 删除电池
export function deleteBattery(batteryId) {
  return request({
    url: `/system/battery/${batteryId}`,
    method: 'delete'
  })
}

// 更新电池状态
export function updateBatteryStatus(batteryId, status) {
  return request({
    url: `/system/battery/${batteryId}/status`,
    method: 'put',
    data: { status }
  })
}

// 电池充电记录
export function getBatteryChargeHistory(batteryId) {
  return request({
    url: `/system/battery/${batteryId}/charge-history`,
    method: 'get'
  })
}

// 报表统计相关接口

// 获取换电订单统计报表
export function getOrderStatisticsReport(params) {
  return request({
    url: '/system/battery-order/report/statistics',
    method: 'get',
    params
  })
}

// 获取换电效率报表
export function getChangeEfficiencyReport(params) {
  return request({
    url: '/system/battery-order/report/efficiency',
    method: 'get',
    params
  })
}

// 获取平台使用率报表
export function getPlatformUsageReport(params) {
  return request({
    url: '/system/battery-order/report/platform-usage',
    method: 'get',
    params
  })
}

// 获取换电车工作量报表
export function getTruckWorkloadReport(params) {
  return request({
    url: '/system/battery-order/report/truck-workload',
    method: 'get',
    params
  })
}

// 导出订单数据
export function exportOrderData(params) {
  return request({
    url: '/system/battery-order/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 实时监控相关接口

// 获取实时订单状态
export function getRealTimeOrderStatus() {
  return request({
    url: '/system/battery-order/real-time/status',
    method: 'get'
  })
}

// 获取平台实时状态
export function getRealTimePlatformStatus() {
  return request({
    url: '/system/charging-platform/real-time/status',
    method: 'get'
  })
}

// 获取换电车实时位置
export function getRealTimeTruckLocation() {
  return request({
    url: '/system/battery-truck/real-time/location',
    method: 'get'
  })
}

// 系统配置相关接口

// 获取调度配置
export function getDispatchConfig() {
  return request({
    url: '/system/battery-order/config/dispatch',
    method: 'get'
  })
}

// 更新调度配置
export function updateDispatchConfig(data) {
  return request({
    url: '/system/battery-order/config/dispatch',
    method: 'put',
    data
  })
}

// 获取告警配置
export function getAlertConfig() {
  return request({
    url: '/system/battery-order/config/alert',
    method: 'get'
  })
}

// 更新告警配置
export function updateAlertConfig(data) {
  return request({
    url: '/system/battery-order/config/alert',
    method: 'put',
    data
  })
}